package edu.unh.sustain;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class ZipcarActivity extends Activity
{
	String url = "http://www.zipcar.com/unh/";
	WebView mWebView;
	final Activity act = this;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.zipcar);
	    
	    mWebView = (WebView)findViewById(R.id.zipcar_webview);
	    this.setProgressBarIndeterminate(true);
	    mWebView.getSettings().setJavaScriptEnabled(true);
	    mWebView.setInitialScale(1);
	    mWebView.setWebViewClient(new WebViewClient()
	    {
	    	/**
	    	 * loads URLs within the app, instead of the native browser
	    	 */
			public boolean shouldOverrideUrlLoading(WebView view, String url)
			{
				view.loadUrl(url);
				return false;
			}
	    });
	    
	    mWebView.loadUrl(url);
	}
	
	/**
	 * Handles the back button in the webview.  If it can go back to a previous
	 * page, it does. If not, it will return to the Transportation menu.
	 */
	@Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
	{
        if(event.getAction() == KeyEvent.ACTION_DOWN)
        {
            switch(keyCode)
            {
	            case KeyEvent.KEYCODE_BACK:
	                if(mWebView.canGoBack() == true)
	                {
	                    mWebView.goBack();
	                }
	                else
	                {
                		finish();
	                }
	                return true;
            }
        }
        
        return super.onKeyDown(keyCode, event);
    }

}
